﻿using DJ.Clients;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DJ.Dialog
{
    /// <summary>
    /// DeviceEdit.xaml 的交互逻辑
    /// </summary>
    public partial class DeviceEdit : Window
    {
        public DeviceEdit()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
            string[] strs = SerialPort.GetPortNames();
            foreach (string str in strs)
            {
                com.Items.Add(str);
            }
        }

        private void Button_Edit(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(name.Text))
            {
                MessageDialog.ShowDialog("设备名称不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(com.Text))
            {
                MessageDialog.ShowDialog("COM口不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(baud.Text))
            {
                MessageDialog.ShowDialog("波特率不能为空");
                return;
            }
            this.DialogResult = true;
        }

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            base.DragMove();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void TextBox1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ComWindow.Focus(sender);
            e.Handled = true;
        }

    }
}
